//
// Created by tanke on 23-11-21.
//

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int countQuadruplets(int* nums, int numsSize)
{
    int ret = 0;

    for(int i = 3; i < numsSize; i ++) {
        for (int m = 0; m < i - 2; m ++) {
            for (int n = m + 1; n < i - 1; n ++) {
                for (int t = n + 1; t < i; t ++) {
                    int sum = nums[m] + nums[n] + nums[t];
                    if (sum == nums[i]) {
                        //printf("found: %d + %d + %d = %d\n", nums[m], nums[n], nums[t], nums[i]);
                        ret += 1;
                    }
                }
            }
        }
    }
    return ret;
}


int main(void)
{
    int nums1[5] = {1, 1, 1, 3, 5};
    printf("%d\n", countQuadruplets(nums1, 5));

    int nums2[9] = {56,50,33,1,86,80,85,42,90};
    printf("%d\n", countQuadruplets(nums2, 9));

    return 0;
}
